package com.app.logrecord.service.impl;

import cn.hutool.core.util.StrUtil;
import com.app.logrecord.mapper.OperationFieldMapper;
import com.app.logrecord.pojo.dto.OperationFieldPageDto;
import com.app.logrecord.pojo.po.OperationField;
import com.app.logrecord.service.OperationFieldService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;

/**
 * @author qiangt
 * @version 1.0
 * @date 2024/3/29 14:35
 * @description: 操作记录字段service实现类
 */
@Validated
@Service
public class OperationFieldServiceImpl extends ServiceImpl<OperationFieldMapper, OperationField> implements OperationFieldService {
    @Override
    public Page<OperationField> pageByOperationId(@Valid OperationFieldPageDto pageDto) {
        Page<OperationField> page = new Page<>(pageDto.getPageCurrent(), pageDto.getPageSize());
        String orderSql = pageDto.getOrderSql();
        return this.lambdaQuery()
                .eq(OperationField::getOperationId, pageDto.getOperationId())
                .last(StrUtil.isNotBlank(orderSql), orderSql)
                .orderByDesc(StrUtil.isBlank(orderSql), OperationField::getCreateTime)
                .page(page);
    }
}
